import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import { RegisterUserInputDto } from '../dto/register.user.dto';
import { UserService } from '../../services/user/user.service';
import { UserEntity } from '../../entities/user.entity';
import { LoginUserInputDto } from '../dto/login.user.dto';
import { LoginVo } from 'src/modules/common/auth/vo/login.vo';
import { CurrentUser, ICurrentUserType } from 'src/decorators/current.user';
import { UseGuards } from '@nestjs/common';
import { AuthGuard } from 'src/guard/auth.guard';

@Resolver()
export class UserResolver {
  constructor(private readonly userService: UserService){}

  @Mutation(() => String, { nullable: false, description: '测试用户注册' })
  async register(@Args('data') registerUserInputDto: RegisterUserInputDto): Promise<string> {
    console.log('提交的数据', registerUserInputDto);
    return await this.userService.register(registerUserInputDto);
  }

  @Query(() => LoginVo, {description: '登录接口'})
  async login(@Args('data') loginUserInputDto:LoginUserInputDto): Promise<LoginVo>{
    return await this.userService.login(loginUserInputDto)
  }

  @UseGuards(AuthGuard)
  @Query(() => [UserEntity!]!, {description: '查询用户列表'})
  async userList(
    @CurrentUser() userInfo: ICurrentUserType
  ): Promise<UserEntity[]>{
    return await this.userService.userList()
  }
}
